import sys

from confs import WINSIZE, is_word

def main():
    '''
    NOTE: no reducer for this job
    input: corpus.txt;
    output: links_first.txt
    (line) -> (word1 'r:'word2) where word2 is a right neighbour of word1
           -> (word <) if word surely has left boundary
           -> (word >) if word surely has right boundary
    '''
    for line in sys.stdin:
        line = line.strip()
        l = len(line)
        for i in range(l):
            for j in range(i + 1, min(i + WINSIZE + 1, l + 1)):
                x = line[i: j]
                if not is_word(x):
                    continue
                y = line[j: min(j + WINSIZE, l)]
                if y:
                    print '%s\tr:%s' % (x, y)

        for i in range(1, min(WINSIZE + 1, l + 1)):
            x = line[: i]
            if not is_word(x): continue
            print '%s\t<' % x
        for i in range(l - 1, max(l - WINSIZE - 1, -1), -1):
            x = line[i: ]
            if not is_word(x): continue
            print '%s\t>' % x

if __name__ == '__main__':
    main()
